<template>
    <el-menu
      class="sidebar-menu"
      :default-active="activeMenu"
      router
      unique-opened
    >
      <el-menu-item index="/admin/dashboard">
        <el-icon><PieChart /></el-icon>
        <span>仪表盘</span>
      </el-menu-item>
  
      <el-sub-menu index="1">
        <template #title>
          <el-icon><User /></el-icon>
          <span>用户管理</span>
        </template>
        <el-menu-item index="/admin/users/list">用户列表</el-menu-item>
        <!-- <el-menu-item index="/admin/users/audit">审核管理</el-menu-item> -->
      </el-sub-menu>
  
      <el-sub-menu index="2">
        <template #title>
          <el-icon><ShoppingCart /></el-icon>
          <span>商品管理</span>
        </template>
        <el-menu-item index="/admin/products/list">商品列表</el-menu-item>
        <el-menu-item index="/admin/products/categories">分类管理</el-menu-item>
      </el-sub-menu>
  
      <el-sub-menu index="3">
        <template #title>
          <el-icon><Tickets /></el-icon>
          <span>订单管理</span>
        </template>
        <el-menu-item index="/admin/orders/list">所有订单</el-menu-item>
        <el-menu-item index="/admin/orders/refund">退款处理</el-menu-item>
      </el-sub-menu>
  
      <el-sub-menu index="4">
        <template #title>
          <el-icon><ChatDotRound /></el-icon>
          <span>论坛管理</span>
        </template>
        <el-menu-item index="/admin/forum/posts">帖子管理</el-menu-item>
        <el-menu-item index="/admin/forum/comments">评论审核</el-menu-item>
      </el-sub-menu>
    </el-menu>
  </template>
  
  <script setup>
  import { ref, watch } from 'vue'
  import { useRoute } from 'vue-router'
  import {
    PieChart,
    User,
    ShoppingCart,
    Tickets,
    ChatDotRound
  } from '@element-plus/icons-vue'
  
  const route = useRoute()
  const activeMenu = ref(route.path)
  
  watch(
    () => route.path,
    (newPath) => {
      activeMenu.value = newPath
    }
  )
  </script>
  
  <style scoped>
  .sidebar-menu {
    width: 240px;
    height: 100vh;
    border-right: 1px solid #e6e6e6;
    background: #f8f9fa;
  }
  
  .el-menu-item,
  .el-sub-menu__title {
    height: 48px;
    line-height: 48px;
  }
  
  .el-icon {
    margin-right: 8px;
    font-size: 18px;
  }
  </style>